package com.mt.skyhoist.util.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.mt.skyhoist.R;
public class GroupView extends LinearLayout {

    private Context context;

    public GroupView(Context context) {
        super(context);
        this.context = context;

        initView();
    }

    // 初始化控件
    private ToggleButton deviceTogglebtn;
    private ToggleButton devicenameBtn;
    private ToggleButton assignTogglebtn;
    private TextView devicename2Tv;

    private void initView() {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.fmt_group, this);

        deviceTogglebtn = (ToggleButton) findViewById(R.id.device2_togglebtn);
        devicenameBtn = (ToggleButton) findViewById(R.id.devicename2_btn);
        assignTogglebtn = (ToggleButton) findViewById(R.id.assign2_togglebtn);
        devicename2Tv = findViewById(R.id.devicename2_tv);

        devicenameBtn.setOnClickListener(myOnClickListener);
    }

    private GroupFmtBean data;

    public void setData(GroupFmtBean data) {
        this.data = data;
//        devicenameBtn.setTextOn("Station " + (data.getTag() + 1));
//        devicenameBtn.setTextOff("Station " + (data.getTag() + 1));
        devicename2Tv.setText("Station " + (data.getTag() + 1));
        devicenameBtn.setChecked(data.isToggleButtonEnable());
        assignTogglebtn.setChecked(data.isAssignButtonEnable());
    }

    private Callback callback;

    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    // 按钮监听
    private OnClickListener myOnClickListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            callback.onToggleClick(data, devicenameBtn.isChecked());
        }
    };

    public static class GroupFmtBean {
        private int Tag;
        private boolean toggleButtonEnable;
        private boolean assignButtonEnable;

        public boolean isToggleButtonEnable() {
            return toggleButtonEnable;
        }

        public void setToggleButtonEnable(boolean toggleButtonEnable) {
            this.toggleButtonEnable = toggleButtonEnable;
        }

        public boolean isAssignButtonEnable() {
            return assignButtonEnable;
        }

        public void setAssignButtonEnable(boolean assignButtonEnable) {
            this.assignButtonEnable = assignButtonEnable;
        }

        public int getTag() {
            return Tag;
        }

        public void setTag(int tag) {
            Tag = tag;
        }
    }

    public interface Callback {
        void onToggleClick(GroupFmtBean data, boolean enable);

        void onNameLongClick(GroupFmtBean data);
    }

}
